<?php
require "./boot.php";
require "./app.php";
$ip=$_SERVER["REMOTE_ADDR"];
$userMac   = strtoupper(exec("cat /proc/net/arp |grep $ip|awk '{print $4}'"));
?>
<!doctype html>
<html ng-app = "index" ng-controller="index_controller">
<head>
    <meta charset="UTF-8">
    <title>{%$app.app_name%}</title>
    <meta name="viewport" content="width=device-width,height=device-height initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="./assets/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="./assets/css/bootstrap-theme.min.css"/>
    <script type="text/javascript" src="./assets/js/jquery-1.8.1.min.js"></script>
    <script type="text/javascript" src="./assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../__S__/s.js"></script>
    <link rel="stylesheet" href="./assets/css/list.css"/>
    <link rel="stylesheet" href="./assets/css/header.css"/>
    <link rel="stylesheet" href="./../__ASSETS__/css/header.css">
</head>
<body>
<header class="header-fix text-center" id='header'>
    <a class="homepage" href="./../home/"><i class="glyphicon glyphicon-home"></i></a>
    <div class="header_title" id="title">意见反馈</div>
</header>
<div class="container" style="margin-top: 50px">
<?php
function varify_url(){
    $url = "https://www.baidu.com/";
   // $check = fopen($url,'r');
    /*$ch=curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $check = curl_exec($ch);*/
    // $box = exec("sh /jffs/bin/pingstat.sh");
    $box = file_exists('/tmp/neton');
    if($box === false){
        /*if($check) //不在盒端就在本地写吧
            $status = true;
        else*/
            $status = false;
    }else{
        $status = true;
    }
    return $status;
}
$online = varify_url();
if( $online == true){//用户联网
    echo '<div class="row">
        <div id="myForm">
            <textarea id="onlineContent" class="chatInput" placeholder="请输入您的宝贵意见,字数限制在150字以内" maxlength="200" name="content" style="height: 130px;width: 100%;margin-top: 10px;"></textarea>
            <input id="Mac" type="hidden"  name="mac" value="<? echo $userMac ?>">
            <button class="btn btn-success"  onclick="CreateComment()"  style="width:100%">提交</button>
        </div>
        <div id="content-wrapper" style="display: block;">
        </div>
    </div>';
}
else{
    echo '<div class="row">
        <form id="myForm"  method="POST" action="create.php" onsubmit="return check()">
            <textarea id="content" class="chatInput" placeholder="请输入您的宝贵意见,字数限制在200字以内" maxlength="200" name="content" style="height: 130px;width: 100%;margin-top: 10px;"></textarea>
            <input  type="hidden"  name="mac" value="<? echo $userMac ?>">
            <button class="btn btn-success" type="submit"  style="width:100%">提交</button>
        </form>
        <div id="content-wrapper" style="display: block;">
        </div>
    </div>';
}
?>
</div>
</body>
<script>
    $(function(){
        <?php if(varify_url() == true){?>
            $.ajax({
            url:'./link.php',
            dataType:'json',
            type:'get',
            success:function(b){
                if(b.success){
                    console.log(b.data);//向盒端请求数据
                    $.ajax({
                        url:b.data,
                        dataType:'jsonp',
                        type:'get',
                        success:function(comment){
                            if(comment.success)
                            {
                                var html;
                                for(var i = 0;i < comment.data.length;i++)
                                {
                                    var info = comment.data[i];
                                    if(i == 0)
                                    {
                                        html = "<div class='panel panel-success'><div class='panel-body'><h5>"
                                            +info.advice_content+"</h5><p class='text-muted' style='float: right;margin:1px 0 0px'><em style='font-size: 13px'>" +info.createtime+ "</em></p></div></div>";
                                    }
                                    else
                                    {
                                        html += "<div class='panel panel-success'><div class='panel-body'><h5>"
                                            +info.advice_content+"</h5><p class='text-muted' style='float: right;margin:1px 0 0px'><em style='font-size: 13px'>" +info.createtime+ "</em></p></div></div>";
                                    }
                                }
                                if(i == 0)
                                    var html = "<div class='panel panel-success'><div class='panel-body'>请作为第一个给我们建议的人吧，谢谢！<p class='text-muted' style='float: right'><em style='font-size: 13px'>" + "</em></p></div></div>";
                                $("#content-wrapper").append(html);
                            }
                        }
                    });
                }
                else
                {
                    alert("请检查是否联网");
                }
            }
        });
        <?php }
         else{ ?>
            $.ajax({
            url:'./result.php',
            dataType:'json',
            success:function(resp){
                if(resp.success)
                {
                    var html;
                    for(var i = 0;i < resp.data.length;i++)
                    {
                        var info = resp.data[i];
                        if(i == 0)
                        {
                            html = "<div class='panel panel-success'><div class='panel-body'><h5>"
                                +info.content+"</h5><p class='text-muted' style='float: right;margin:1px 0 0px'><em style='font-size: 13px'>" +info.createtime+ "</em></p></div></div>";
                        }
                        else
                        {
                            html += "<div class='panel panel-success'><div class='panel-body'><h5>"
                                +info.content+"</h5><p class='text-muted' style='float: right;margin:1px 0 0px'><em style='font-size: 13px'>" +info.createtime+ "</em></p></div></div>";
                        }
                    }
                    $("#content-wrapper").append(html);

                }
                else{
                    var html = "<div class='panel panel-success'><div class='panel-body'>请作为第一个给我们建议的人吧，谢谢！<p class='text-muted' style='float: right'><em style='font-size: 13px'>" + "</em></p></div></div>";
                    $("#content-wrapper").append(html);
                }
            }
        });
         <?php }?>
    });

    function check(){
        if($('#content').val()!='')
            return true;
        else{
            alert("请您先输入内容在提交哦，谢谢！");
            return false;
        }
    }
    function CreateComment(){//联网状态创建评论
        if($("#onlineContent").val()==''){
            alert("请您先输入内容在提交哦，谢谢！");
            return;
        }
        $.ajax({
            url:'./onlineCreate.php',
            dataType:'json',
            data: {mac:$("#mac").innerHTML, content: $("#onlineContent").val()},
            success:function(resp){
                if(resp.success){
                    console.log(resp.data);//向盒端请求数据
                    var content = $("#onlineContent").val();
                    $.ajax({
                        url:resp.data,
                        dataType:'jsonp',
                        type:'get',
                        data: {mac:$("#mac").innerHTML, content:content},
                        success:function(comment){
                            if(comment.success)//数据提交成功
                            {
                                if(comment.data == 'ok')
                                    document.location.reload();
                            }
                            else{
                                    alert("抱歉,数据提交失败请重试");
                            }
                        }
                    });
                }
                else
                {
                    alert("请检查是否联网");
                }
            }
        });
    }
</script>
</html>
